package com.atguigu.myjuc.mythread.day2;

import java.util.concurrent.BrokenBarrierException;
import java.util.concurrent.CyclicBarrier;
//累计达到parties发生召唤神龙
public class CyclicBarrierDemo {
    public static void main(String[] args) throws BrokenBarrierException, InterruptedException {
        CyclicBarrier cyclicBarrier = new CyclicBarrier(7,()->{System.out.println("神龙：年轻人，你的愿望是什么");});
        for (int i = 1; i <=7; i++) {
            int finalI = i;
            new Thread(()->{
                System.out.println("获得了"+ finalI +"星珠");
                try {
                    cyclicBarrier.await();
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                } catch (BrokenBarrierException e) {
                    throw new RuntimeException(e);
                }
            },String.valueOf(i)).start();

        }


        }

}
